//
//  Algorithm.c
//  Algorithm
//
//  Created by zlmac on 16/7/30.
//  Copyright © 2016年 godHands. All rights reserved.
//

#include "Algorithm.h"

int  searchKKK(int *a,int k,int length){
    
    if (k>length) {
        printf("不存在第%d大数字",k);
    }
    else{
        for (int j=0; j<length; j++) {
            int max=a[0];
            int flag=0;
            for (int i=1; i<length-j; i++) {
                if (a[i]>max) {
                    max=a[i];
                    flag=i;
                }
            }
            if (j==k-1) {
                return a[flag];
            }
            if (flag!=length-j-1) {
                int tmp=a[flag];
                a[flag]=a[length-j-1];
                a[length-j-1]=tmp;
            }
        }
    }
    return -10000;
}